package com.jhws.business.device.bo;

import com.jhws.business.device.service.DeviceService;
import com.jhws.core.dataUpdate.bo.DataUpdateObject;
import com.jhws.core.dataUpdate.bo.IDataUpdateModule;
import com.jhws.core.dataUpdate.service.DataUpdateService;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class DeviceUpdateData implements IDataUpdateModule{

    public static final String DEV_FACE_PERM = "dev_face_perm";
    private String [] name = {DEV_FACE_PERM};

    @Resource
    DataUpdateService dataUpdateService;
    @Resource
    DeviceService deviceService;

    @Override
    public String[] getModuleName() {
        return name;
    }

    @Override
    public DataUpdateObject getUserModuleData(String username, String ownerCode,Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {
        List<Boolean> list = new ArrayList<Boolean>();
        if(deviceService.getDevFaceRegistered(username) == null) {
            list.add(false);
            return new DataUpdateObject(list);
        }
        list.add(true);
        return new DataUpdateObject(list);
    }

    @Override
    public DataUpdateObject getLabelModuleData(String label, Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {
        return null;
    }

    @Override
    @PostConstruct
    public void registerModule() {
        dataUpdateService.registerModule(this);
    }
}
